/**
 * 任务订单
 *
 * @project sky-take-out_1
 * @author MECHREVO
 * @date 2023/12/15 09:55:17
 * @version 1.0
 */
package com.sky.Task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
@Slf4j
public class OrderTask {

    @Autowired
    private OrderMapper orderMapper;

    //@Scheduled(cron = "0 0/1 * * * ?")
    public void autoCancelOrder() {
        log.info("--------自动取消订单:开始-------------");
        //  LocalDateTime now = LocalDateTime.now();
        //  LocalDateTime time = now.plusMinutes(-15);
        //  List<Orders>ordersList=orderMapper.selectListCancellation(time);
        //log.info("-------查询超时订单：{}个---------",ordersList.size());
        //  if(!ordersList.isEmpty()){
        //      ordersList.forEach(orders->{
        //          orders.setStatus(Orders.CANCELLED);
        //          orders.setCancelReason("超时自动取消");
        //          orders.setCancelTime(LocalDateTime.now());
        //          orderMapper.updateById(orders);
        //      });
        //  }
        orderMapper.updateStatusBeforeTime();
        log.info("--------自动取消订单:结束-------------");
    }

   // @Scheduled(cron = "0 0 2 * * ?")
        public void updateStatusBystatus(){
        log.info("--------自动完成订单:开始-------------");
        orderMapper.updateStatusBystatus();
        log.info("--------自动完成订单:结束-------------");
        }
}
